home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-22 | 2.5 KB | 124 lines | [TEXT/MPS ] |
-
- //============================================================
- #ifndef _MYINDIVIDUAL_
- #include "MyIndividual.h"
- #endif
-
- #ifndef _POPULATION_
- #include "Population.h"
- #endif
-
- #ifndef _CIRCLECITYMAP_
- #include "CircleCityMap.h"
- #endif
-
- #ifndef _PATHGRAPH_
- #include "PathGraph.h"
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __EVENTS__
- #include <Events.h>
- #endif
-
- #ifndef __FONTS__
- #include <Fonts.h>
- #endif
-
- /*
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
- */
-
- #ifndef __QUICKDRAW__
- #include <Quickdraw.h>
- #endif
-
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #ifndef _GAFAILURE_
- #include "GAFailure.h"
- #endif
-
- extern GrafPtr thePort; // for Random()
-
-
- //============================================================
- void
- main()
- {
- short numberIndividuals = 200;
- short numberGenerations = 25;
- float mutationRate = .01;
- float crossoverRate = .6;
- int numberCities = 16;
-
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- // InitMenus();
- TEInit();
- InitDialogs( NULL );
- InitCursor();
-
- TCityMap* cityMap = new TCircleCityMap( numberCities );
- FailNIL(cityMap);
- TMyIndividual* prototype = new TMyIndividual( cityMap );
- FailNIL(prototype);
- TPopulation pop( numberIndividuals, mutationRate, crossoverRate, prototype);
-
- WindowPtr theWindow;
- Rect rBounds = { 40, 40, 400, 400 };
- theWindow = NewWindow( NULL, &rBounds, "\pPlotting Window", TRUE, documentProc,
- (WindowPtr)-1L, TRUE, 0L );
-
- TPathGraph* pathGraph = new TPathGraph ( *cityMap, theWindow, theWindow->portRect );
- FailNIL(pathGraph);
- SetPort( theWindow );
- pathGraph->PlotCityLocations();
-
- EventRecord event;
- unsigned char numText[16];
- short* importanceArray = new short[ numberCities ];
- FailNIL(importanceArray);
- //TIndividual& bestIndividual = pop.GetBestIndividual();
- TIndividual* bestIndividual = &(pop.GetBestIndividual());
- for ( short generation = 0; generation < numberGenerations; ++generation )
- {
- GetNextEvent( everyEvent, &event );
- pop.NextGeneration();
- EraseRect( &theWindow->portRect );
- pathGraph->PlotCityLocations();
- bestIndividual = &(pop.GetBestIndividual());
- for (short geneIndex = 0; geneIndex < numberCities; ++geneIndex )
- importanceArray[ geneIndex ] = bestIndividual->GetGene( geneIndex ).GetValue();
- pathGraph->PlotRoute( importanceArray );
- }
-
- while( !Button() )
- GetNextEvent( everyEvent, &event );
- while( Button() )
- GetNextEvent( everyEvent, &event );
-
- DisposeWindow( theWindow );
-
-
-
- }
-
-
-